<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="tld" uri="/WEB-INF/tld/rei.tld" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@include file="/WEB-INF/include/admin-head.jsp" %>
<body>
<div class="ok-body">

	<!--数据表格-->
	<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script><script src="/static/js/jquery.min.js"></script>
<script>
	layui.use(["element", "jquery", "table", "form", "laydate", "okLayer", "okUtils", "okMock"], function () {
		let table = layui.table;
		let form = layui.form;
		let laydate = layui.laydate;
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;
		let okMock = layui.okMock;
		let $ = layui.jquery;

		laydate.render({elem: "#startTime", type: "datetime"});
		laydate.render({elem: "#endTime", type: "datetime"});
		okLoading.close($);
		let userTable = table.render({
			elem: '#tableId',
			url: '/admin/orders/list/data?state=3',
			limit: 20,
			page: true,
			toolbar: true,
			toolbar: "#toolbarTpl",
			size: "lg",
			cols: [[
			    	{type: "checkbox", fixed: "left"},



                        {field: "id", title: "序号", width: 160},

                        {field: "userId", title: "理赔人", width: 160},

                        {field: "price", title: "赔偿金额", width: 160},

                        {field: "createDate", title: "申请时间", width: 160},

                        {field: "insuranceId", title: "保单", width: 160},

                        {field: "carNo", title: "车险车辆", width: 160},

                        {field: "description", title: "描述", width: 160},

                        {field: "state", title: "调查详情", width: 100, templet: "#diaocha"},
                        {field: "state", title: "勘察详情", width: 100, templet: "#kancha"},

				{title: "操作", width: 250, align: "center", fixed: "right", templet: "#operationTpl"}
			]],
			done: function (res, curr, count) {
				console.info(res, curr, count);
			}
		});

		form.on("submit(search)", function (data) {
			userTable.reload({
				where: data.field,
				page: {curr: 1}
			});
			return false;
		});

		table.on("toolbar(tableFilter)", function (obj) {
			switch (obj.event) {
				case "batchEnabled":
					batchEnabled();
					break;
				case "batchDisabled":
					batchDisabled();
					break;
				case "batchDel":
					batchDel();
					break;
				case "add":
					add();
					break;

			}
		});

		table.on("tool(tableFilter)", function (obj) {
			let data = obj.data;
			switch (obj.event) {
				case "edit":
					edit(data);
					break;
				case "approve":
                    approve(data.id);
					break;
				case "refuse":
					refuse(data.id);
					break;
				case "kancha":
					kancha(data.id);
					break;
				case "diaocha":
					diaocha(data.id);
					break;
			}
		});


		function add() {
			okLayer.open("添加", "/admin/orders/add", "90%", "90%", null, function () {
				userTable.reload();
			})
		}

		function edit(data) {
			okLayer.open("更新", "/admin/orders/edit?id="+data.id, "90%", "90%", function (layero) {
			}, function () {
				userTable.reload();
			})
		}

		function approve(id) {
			okLayer.confirm("确定发放赔偿金？", function () {
				$.post("/admin/orders/approved",{id: id,state:5},function (result) {
					if (result.code == 0){
						layer.alert("赔偿金已发放至用户账户",{icon:1},function () {
							location.reload();
						})
					}else {
						layer.msg(result.message);
					}
				})
			});
		}
		function kancha(id) {
			okLayer.open("勘察记录", "/admin/responsibility/kancha?id=" + id, "90%", "90%", null, function () {
				userTable.reload();
			})

		}
		function diaocha(id) {
			okLayer.open("调查记录", "/admin/investigation/diaocha?id=" + id, "90%", "90%", null, function () {
				userTable.reload();
			})

		}
		function refuse(id) {
			okLayer.confirm("确定驳回吗？", function () {
				$.post("/admin/orders/approved",{id: id,state:4},function (result) {
					if (result.code == 0){
						layer.alert("已驳回",{icon:1},function () {
							location.reload();
						})
					}else {
						layer.msg(result.message);
					}
				})
			});
		}
	})
</script>

<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
	<button class="layui-btn layui-btn-sm" lay-event="approve">通过</button>
	<button class="layui-btn layui-btn-sm layui-bg-red " lay-event="refuse">驳回</button>
</script>

<script type="text/html" id="diaocha">
	<span class="layui-btn layui-btn-warm layui-btn-xs" lay-event="diaocha">查看</span>

</script>

<script type="text/html" id="kancha">
	<span class="layui-btn layui-btn-warm layui-btn-xs" lay-event="kancha">查看</span>
</script>

</body>
</html>

